package view;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controller.ACSystem;

import javax.swing.JLabel;

import model.Auction;
import model.AuctionCalendar;
import model.AuctionCentralEmployee;
import model.Bidder;
import model.WestPanelEnum;

import javax.swing.border.LineBorder;

import java.awt.Color;
/**
 * 
 * @author Bob Landowski
 *
 */
@SuppressWarnings({"unused", "serial"})
public class EastPanelACDir extends JPanel {

	/** The ACcontroller */
	private ACSystem my_ACcontroller;
	
	/** The East Panel ACE*/
	private EastPanelACE my_EastPanelACE;
	
	/** The bidderSearchField */
	private JTextField bidderSearchField;
	
	/** The main frame */
	private JFrame my_mainframe;
	
	/** The found bidder */
	private Bidder found_bidder;
	
	/** The auction selected */
	private String auctionSelected;
	
	/** The auction searched */
	private Auction auctionSearched;
	
	/** The auction calendar */
	private AuctionCalendar my_auction_calendar;
	private JTextField employeeSearchField;

	/**
	 * Create the panel.
	 */
	public EastPanelACDir(final ACSystem the_ACcontroller) {
		setBorder(new LineBorder(new Color(0, 0, 0), 5));
		my_ACcontroller = the_ACcontroller;
		my_auction_calendar = my_ACcontroller.getAuctionCalendar();
		setLayout(null);
		setPreferredSize(new Dimension(180, 400));

		JButton calendarButton = new JButton("Calendar");
		calendarButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				my_ACcontroller.setWestPanel(WestPanelEnum.CALENDAR);
				my_ACcontroller.getMainFrame().westPanelState(new Object());
			}
		});
		calendarButton.setBounds(15, 26, 148, 29);
		add(calendarButton);

		JButton exitButton = new JButton("Exit");
		exitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		exitButton.setBounds(15, 355, 148, 29);
		add(exitButton);

		JButton reqAuctionButton = new JButton("Bidder Search");
		reqAuctionButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				found_bidder = (Bidder) my_ACcontroller.findUser(bidderSearchField.getText());
				if (found_bidder == null) {
					bidderSearchField.setBackground(new Color(255,50,50));
				} else {
					bidderSearchField.setBackground(new Color(255,255,255));
					my_ACcontroller.setWestPanel(WestPanelEnum.BIDDER);
					my_ACcontroller.getMainFrame().westPanelState(found_bidder);
				}
			}
		});

		reqAuctionButton.setBounds(15, 216, 148, 29);
		add(reqAuctionButton);

		bidderSearchField = new JTextField();
		bidderSearchField.setBounds(17, 186, 146, 26);
		add(bidderSearchField);
		bidderSearchField.setColumns(10);

		JButton listAuctionButton = new JButton("List Auctions");
		listAuctionButton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				Object[] possibilities = new Object[my_ACcontroller
				                                    .getAuctionList().size()];
				for (int i = 0; i < my_ACcontroller.getAuctionList().size(); i++) {
					possibilities[i] = my_ACcontroller.getAuctionList().get(i)
							.getName();
				}

				auctionSelected = (String) JOptionPane.showInputDialog(
						my_mainframe, "Choose your Auction", "Auction chooser",
						JOptionPane.PLAIN_MESSAGE, null, possibilities, null);
				if (auctionSelected != null) {				
					auctionSearched = my_auction_calendar.findAuction(auctionSelected);	
					my_ACcontroller.setWestPanel(WestPanelEnum.AUCTION);
					my_ACcontroller.getMainFrame().westPanelState(auctionSearched);
				}
			}

		});
		listAuctionButton.setBounds(15, 76, 148, 29);
		add(listAuctionButton);
	
	JButton addItemButton = new JButton("Add Item");
	addItemButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			my_ACcontroller.setWestPanel(WestPanelEnum.ITEMINPUT);
			my_ACcontroller.getMainFrame().westPanelState(new Object());
			
		}
	});
	addItemButton.setBounds(15, 126, 148, 29);
	add(addItemButton);
	
	JButton employeeSearchButton = new JButton("Employee Search");
	employeeSearchButton.addActionListener(new ActionListener() {
		private AuctionCentralEmployee found_employee;

		public void actionPerformed(ActionEvent e) {
			found_employee = (AuctionCentralEmployee) my_ACcontroller.findUser(employeeSearchField.getText());
			if (found_employee == null) {
				employeeSearchField.setBackground(new Color(255,50,50));
			} else {
				employeeSearchField.setBackground(new Color(255,255,255));
				my_ACcontroller.setWestPanel(WestPanelEnum.ACEMPLOYEE);
				my_ACcontroller.getMainFrame().westPanelState(found_employee);
			}
		}
	});
	employeeSearchButton.setFont(new Font("Tahoma", Font.PLAIN, 15));
	employeeSearchButton.setBounds(15, 306, 148, 29);
	add(employeeSearchButton);
	
	employeeSearchField = new JTextField();
	employeeSearchField.setBounds(15, 276, 146, 26);
	add(employeeSearchField);
	employeeSearchField.setColumns(10);
}
}
